/* eslint-disable prettier/prettier */
import { Injectable } from '@nestjs/common';
import { CreateDogDto } from './dto/create-dog.dto';
import { UpdateDogDto } from './dto/update-dog.dto';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Dog } from './schemas/dog.schema';

@Injectable()
export class DogsService {
  constructor(@InjectModel(Dog.name) private dogModel: Model<Dog>) { }
  create(createDogDto: CreateDogDto) {
    return this.dogModel.create(createDogDto)
  }

  findAll() {
    return this.dogModel.find().limit(10)
  }

  findOne(id: string) {
    return this.dogModel.findOne({ _id: id })
  }

  async findByName(name: string) {
    return await this.dogModel.find({ name }).limit(10)
  }

  async update(OrderNumber: string, updateDogDto: UpdateDogDto) {
  return  await this.dogModel.findByIdAndUpdate(OrderNumber, updateDogDto)
    // const flag = await this.dogModel.find({ OrderNumber })
    // if (flag.length !== 0) {
    //   await this.dogModel.findByIdAndUpdate(OrderNumber, updateDogDto)
    //   return {
    //     code: 200,
    //     msg: "修改成功！",
    //     data: {}
    //   }
    // } else {
    //   return {
    //     code: 200,
    //     msg: "订单号不存在！"
    //   }
    // }
  }

  remove(id: string) {
    return this.dogModel.deleteOne({ _id: id })
  }
}
